<template>
  <div class="container-nobottom">
    <van-tabs v-model="active" :ellipsis="false" @click="tabClick" :sticky="true">
      <template v-for="item in orderTabs">
        <van-tab :title="item.title" :name="item.status" :data-status="item.status">
          <template>
            <van-list
              v-model="loading"
              :finished="finished"
              @load="onLoad"
              loading-text="正在加载..."
            >
              <div class="orderList">

                <template v-for="item in list">
                  <div class="ordermain">
                    <div class="ordertop">
                      <div class="ordertop_shop" :data-mid="item.mid">
                        <span class="shopfont">订单编号：{{item.order.outerid}}</span>
                      </div>
                      <div class="pink">
                        <span v-if="item.order.status == 1">待发货</span>
                        <span v-if="item.order.status == 2">已发货</span>
                        <span v-if="item.order.status == 7">已完成</span>
                        <span v-if="item.order.status == 8">退货/换货</span>

                      </div>
                    </div>

                    <div class="orderbody"  @click="orderdetail(item)">
                      <div class="proimg" v-if="item.goodsList[0].pic">
                        <img :src="item.goodsList[0].pic.indexOf('http')!=-1?item.goodsList[0].pic:downloadUrl+'?fileName='+item.goodsList[0].pic"/>
                      </div>
                      <!-- <div class="proinfo"> -->
                      <div style="flex: 1;-webkit-flex: 1;">
                        <div class="proname">{{item.goodsList[0].goods.title}}</div>
                        <template v-if="item.order.status == 2">
                          <div class="gray-txt">快递公司：{{item.order.expressName}}</div>
                          <div class="gray-txt">快递单号：{{item.order.expressNo}}</div>
                        </template>
                        <div class="gray-txt">{{item.order.addr}}</div>
                      </div>
                      <!-- </div> -->
                      <div class="price">
                        <div class="price-img">¥<span style="font-size: 0.3rem;margin-left: 0.03rem;">{{item.order.totalPrice}}</span></div>
                        <div class="num">x{{item.goodsList.length}}</div>
                        <div class="num" v-if="item.order.payType == 0">积分兑换</div>
                        <div class="num" v-if="item.order.payType == 1">闯关兑换</div>
                      </div>
                    </div>
                    <div style="display: flex;margin-bottom:0.34rem;justify-content: flex-end;">
                      <div style="margin-right: 0.34rem;margin-top: 0.25rem;clear: both;">
                        <template>
                          <span style="font-size: 0.24rem;color: #353535;">共{{item.goodsList.length}}件商品
                            <span>
                              <span style="margin-left: 0.10rem;">订单总额:</span>
                              <span style="color: red;font-weight: bold;">￥<span style="font-size: 0.30rem;">{{item.order.totalPrice}}</span></span>
                            </span>
                          </span>
                        </template>

                      </div>
                    </div>
                    <div style="margin-top: 0;" v-if="item.order.status == 2" class="line"></div>
                    <div class="btnbox">
                      <template v-if="item.order.status == 2">
                        <button  size="mini" class="btn1" @click="confirmTakeGoods(item.order.id)">确认收货</button>
                      </template>
                    </div>
                  </div>
                </template>
              </div>
            </van-list>
          </template>
        </van-tab>
      </template>
    </van-tabs>

    <div class="weui-loadmore weui-loadmore_line" v-if="finished && list.length!=0 && page>1">
      <span class="weui-loadmore__tips">{{loadMsg}}</span>
    </div>
    <template v-if="finished && list.length==0">
      <div class="error-info">
        <div>
          <img src="../../assets/img/yiyenodata.png"/>
        </div>
        <div class="error">您还没有订单哟~</div>
      </div>

    </template>

    <div class="back-home" @click="goHome();">
      <div>返回</div>
      <div>首页</div>
    </div>

  </div>

</template>
<script>
  import orderService from '../../api/orderService';
  import Api from '../../api/api';
  import { Dialog } from 'vant';
  export default {
    name:'prizeList',
    data() {
      return {
        downloadUrl:Api.download,
        orderTabs:[
          {
            title:'全部',
            status:''
          },
          {
            title:'待发货',
            status:1
          },
          {
            title:'已发货',
            status:2
          },
          {
            title:'已完成',
            status:3
          },
          {
            title:'换货',
            status:5
          }
        ],
        active:0,
        timer:null,
        list: [],
        loading: false,
        finished: false,
        loadMsg: '暂无数据',
        totalPage: '',
        page: 1,
        status: '',
        currItem:{}
      }
    },
    watch:{

    },
    methods: {
      goHome() {
        var url = window.location.origin + window.location.pathname+'?vt='+new Date().getTime() + '#/index?auth=1';
        window.location.href = url;
      },
      confirmTakeGoods(id) {
        orderService.confirmTakeGoods({id:id}).then((rsp)=>{
          if(rsp.result) {
            this.$toast('确认收货成功，感谢您的参与！');
            this._resetList();
          }else {
            this.$toast(rsp.errorMsg);
          }
        }).catch((error)=>{
            this.$toast('confirmTakeGoods接口异常'+error);
        });
      },
      goUrl(url) {
        this.$nocacheRouter(url);
      },

      goGoods(prize) {
        this.$nocacheRouter('/goodsDetailGet?id='+prize.goodsId+'&prizeId='+prize.id);
      },
      tabClick(status){
        if(this.status != status) {
          this.status = status;
          this._resetList();
        }
      },
      _resetList() {
        this.finished = true;
        this.$nextTick(function(){
          this.page = 1;
          this.loading = false;
          this.finished = false;
          this.list = [];
        });

      },
      onLoad() {
        var that = this;
        if(this.timer) {
          clearTimeout(this.timer);
        }
        this.timer = setTimeout(() => {
          that.getList();
      }, CONSTANT.LIST_TIMEOUT);
      },
      getList() {
        orderService.pageListForCustomer({currPage:this.page,status:this.status}).then((rsp)=>{
          if(rsp.result) {
          this.loading = false;
          this.list = this.list.concat(rsp.obj.list);
          var totalPage = rsp.obj.totalPage;
          if ((this.page + 1) > totalPage) {
            this.finished = true;
            this.loadMsg = '我是有底线的';
          }else {
            this.page = this.page + 1;
          }
        }else {
          this.$toast(rsp.errorMsg);
        }
      }).catch((error)=>{
          this.$toast('list接口异常'+error);
      });
      }
    },
    mounted(){
      let status = this.$route.query.status;
      if(status) {
        this.status = status;
        this.active = parseInt(status);
      }

    }
  };
</script>

<style scoped>
  .gray-txt {
    font-size: 0.24rem;
    color: #bbb;
    margin-top: 0.1rem;
  }
  .ordermain{
    background: #fff;
    overflow: hidden;
  }
  .ordertop{
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0.28rem;
  }
  .orderbody{
    min-height: 1.75rem;
    padding:0.16rem 0.32rem;
    box-sizing: border-box;
    background: #fafafa;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .pink{
    color: #ff2741;
  }
  .proimg{
    position: relative;
    width: 1.40rem;
    height: 1.40rem;
    margin-right: 0.16rem;
  }
  .proimg img{
    width: 1.40rem;
    height: 1.40rem;
  }
  .proimg text{
    height: 0.30rem;
    line-height: 0.30rem;
    text-align: center;
    color: #fff;
    background: rgba(255,39,65,0.8);
    left: 0;
    top: 0;
    position: absolute;
    font-size: 0.22rem;
    padding: 0.5rem 0.10rem;
  }
  .proname{
    width: 3.84rem;
    color: #353535;
    font-size: 0.24rem;
    overflow: hidden;
    text-overflow:ellipsis;
    display:-webkit-box;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:2;
  }
  .proname text{
    width: 0.28rem;
    height: 0.28rem;
    text-align: center;
    line-height: 0.28rem;
    background: #f3592e;
    display: inline-block;
    vertical-align: 0.04rem;
    font-size: 0.24rem;
    color: #fff;
    margin-right: 0.1rem;
  }
  .price{
    width: 1.30rem;
    padding-top: 0.10rem;
    color: #353535;
    font-size: 0.36rem;
    text-align: right;
  }
  .price .num{
    color: #888888;
    font-size: 0.26rem;
  }
  .orderbot button{
    vertical-align: -0.08rem;
    margin:0rem 0 0rem 0.20rem;
  }

  .orderbot button {
    padding: 0 1em;
  }
  .ordermain{
    width: 100%;
    margin-bottom: 0.16rem;
  }
  .ordermain:last-child {
    margin-bottom: 0;
  }

  .shopfont{
    margin-right: 0.17rem;
  }
  .ordertop_shop{
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .price-img{
    font-size: 0.20rem;
  }
  .line{
    width: 100%;
    height: 1px;
    background-color: #f6f6f6;
    margin-top: 0.32rem;
  }
  .btnbox{
    width: 100%;
    background-color: #ffffff;
    display: flex;
    justify-content: flex-end;

  }

  .btn1{
    width: 1.60rem;
    height: 0.60rem;
    border-radius: 4px;
    border: solid 1px #ff2741;
    font-size: 0.26rem;
    color: #ff2741;
    text-align: center;
    line-height: 0.58rem;
    margin-top: 0.13rem;
    margin-right: 0.32rem;
    margin-bottom: 0.13rem;
    background-color: #ffffff;
  }

  .error-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 1.50rem;
    text-align: center;
  }

  .error-info img{
    width: 2.85rem;
    height: 2.85rem;
  }

  .error-info .error {
    margin-top: 0.40rem;
    font-size: 0.30rem;
    color: #999;
  }

  .error-info .error div{
    font-size: 0.40rem;
  }

  .proimg img.yy-icon {
    height: 0.60rem;
    width: 0.60rem;
    position: absolute;
    left: 0;
    top: 0;
  }

  .refund-num {
    border-radius: 3px;
    font-size: 0.24rem;
    background: #ffe9ec;
    color: #ff2741;
    width: 1rem;
    height:0.4rem;
    line-height:0.4rem;
    margin-bottom: 0.1rem;
    margin-top: 0.1rem;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
